<div class="post">
	<?php if(!$list){ ?>
	
	<div class="buttons">
		<a class="static" href="#" onclick="openBook(<?php echo $data->id; ?>);return false;">Отвори в прозорец</a>
	<?php if(!Yii::app()->user->isGuest){
		$models = Userdata::model()->find('user = '.Yii::app()->user->id);

		if(!empty($models->favorite)){
			if( in_array($data->id,json_decode($models->favorite))){
				$id = "liked"; 
				$text = "Не харесвам";
			}else{	
				$id = "liking";
				$text = "Харесвам";
			}	
		}else{	
			$id = "liking";
			$text = "Харесвам";
		}
	?>
		<a class="<?php echo $id; ?> static" href="#"  onclick="return false;"><?php echo $text; ?></a>
	<?php } ?>	
		<a class="static" href="/post/print/id/<?php echo $data->id; ?>">Принтиране</a>
	</div>
	<?php } ?>
	<div class="title">
		<h1><?php echo CHtml::link(CHtml::encode($data->title), $data->url); ?></h1>
	</div>
	<div class="author">
		Написана от <?php echo $data->author->username . ' на ' . date('d.m.y',$data->create_time); ?>.
	</div>
	<div class="postcontent">
<?php
			
			 if($list){
        echo mb_substr(strip_tags($data->content),0,600,'UTF-8').".......";
    }else{
        $this->beginWidget('CMarkdown', array('purifyOutput'=>true));
			echo $data->content;
			$this->endWidget();
    }
    
		?>
	</div>
	<div class="nav">
		<b>Етикети:</b>
		<?php echo implode(', ', $data->tagLinks); ?>
		<br/>
		<?php echo CHtml::link('Линк', $data->url); ?> |
		<?php echo CHtml::link("Коментари ({$data->commentCount})",$data->url.'#comments'); ?> |
		Последно редактирана на <?php echo date('d.m.y',$data->update_time); ?>
	</div>
</div>

<script type="text/javascript">

$('a.liking').toggle(function() {
  $(this).text('Не харесвам');
  $.get("/system/like/id/<?php echo $data->id; ?>");
}, function() {
  $(this).text('Харесвам');
  $.get("/system/like/id/<?php echo $data->id; ?>");
});

$('a.liked').toggle(function() {
  $(this).text('Харесвам');
  $.get("/system/like/id/<?php echo $data->id; ?>");
}, function() {
  $(this).text('Не харесвам');
  $.get("/system/like/id/<?php echo $data->id; ?>");
});


</script>
